<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>文件测试</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		.nav-tabs li{cursor: pointer;}
	</style>
</head>
<body>
	<sys:message content="${message}"/>
	<div id="content" class="row-fluid">
		
		<div id="right" style="">
			
			
			<div id="queryForm" style="" class="breadcrumb form-search form-horizontal">
				<div id="formAreaId" >
					<div class="control-group" >
						<label class="control-label">CDN服务器类型:</label>
						<select id="serverType" name="serverType" class="input-medium required" value='${serverType}'>
							<option value="aws">亚马逊</option>
						 	<option value="qiniu">七牛云</option>
						 	<option value="aliyun">阿里云</option>
						 	<option value="local">本地</option>
						</select>
					</div>
					<div class="control-group" >
						<label class="control-label">刷新文件Url列表：</label>
						<div class="controls">
							<textarea id="urls" style="width:700px;height: 200px; border: 1px solid #ddd;overflow-y: auto;" ></textarea>
							<br><br>
							<input id="btnFreshCDN" class="btn btn-primary" type="button" value="刷 新CDN" onclick="freshCdn()">
							&nbsp;
							<input id="btnFreshClear" class="btn " type="button" value="清除" onclick="clearUrls()">
						
						</div>
					</div>
					<div class="control-group" >
						<label class="control-label">注：</label>
						<div class="controls">
							<span class="help-inline"><font color="red">
							文件为   http://xxx/dir/file.xxx <br> 路径为  http://xxx/dir/xxx/
							</font> </span>
						</div>
					</div>
				</div>
			</div>
		</div>
		
	</div>
	
<script type="text/javascript">
	//URL
	var listUrl = '${ctx}/fileServer/';
	
	var leftWidth = 180; // 左侧窗口大小
	var htmlObj = $("html"), mainObj = $("#main");
	var frameObj = $("#left, #openClose, #right, #right iframe");
	function wSize(){
		 var strs = getWindowSize().toString().split(",");
		//htmlObj.css({"overflow-x":"hidden", "overflow-y":"hidden"});
		mainObj.css("width","auto");
		frameObj.height(strs[0] - 5);
		var leftWidth = ($("#left").width() < 0 ? 0 : $("#left").width());
		$("#right").width($("#content").width()- leftWidth - $("#openClose").width() -5);
		$(".ztree").width(leftWidth - 10).height(frameObj.height() - 46); 
	}

	
	var serverType = '${serverType}';
	$(document).ready(function() {
		var serverTypeObj = jQuery('#formAreaId').find('[name="serverType"]');
		serverTypeObj.val(serverType);
		serverTypeObj.select2();
		serverTypeObj.css('display', 'none');
		serverTypeObj.attr("disabled", true);
		
	});
	

	function refresh(){
		var url = "/file/fileServer/freshCdnPage";
		url +="?serverType="+serverType;
		window.location = url;
	}

	function clearUrls(){
		jQuery('#urls').val(null);
	}
	function freshCdn(obj){
		var urlsText = jQuery('#urls').val();
		//debugger;
		if(urlsText!=null && urlsText != ''){
			var arrays = urlsText.split('\n');
			if(arrays!=null && arrays.length >0){
				
				var urls = [];
				var dirs = [];
				var flag = true;
				var message = "";
				for (var i = 0; i < arrays.length; i++) {
					var fileUrl =  arrays[i];
					if(fileUrl!=null && fileUrl!=''){
						if(!( fileUrl.startsWith('http://') 
								|| fileUrl.startsWith('https://') )
						){
							flag = false;
							//alertx("url无效 "+fileUrl);
							message = "url无效 "+fileUrl;
							break;
						}else if(fileUrl.endsWith('/')){
							dirs.push(fileUrl);
						}else{
							urls.push(fileUrl);
						}
						
					}
				}
				if(flag &&( dirs.length >0 || urls.length >0 )){
					ajaxFreshCdn(urls.join(','),dirs.join(','));
				}else{
					if(message ==null || message==''){
						message = '请输入有效url';
					}
					alertx(message);
				}
			}
		}else{
			alertx('请输入url');
		}
	}
	
	
	function ajaxFreshCdn(urls,dirs){
		var url = listUrl + 'freshCdn?rk='+Math.random();
		var serverTypeObj = jQuery('#formAreaId').find('[name="serverType"]');
		var serverType = serverTypeObj.val();
		
		if(serverType==null || serverType == ''){
			serverType = 'qiniu';
		}
		var data = {serverType: serverType,urls : urls ,dirs: dirs};
	    jQuery.ajax({  
			url: url, async : false,type: "POST",
			data : data,
			success: function(response) {
				info = response;
				alertx(info.message);
			},
			error: function(e){console.error(e);}
		});
	}
	
</script>
<script src="${ctxStatic}/common/wsize.min.js" type="text/javascript"></script>


</body>
</html>